<h2>Why is this an issue?</h2>
<p>Before Java 8, the only way to partially support closures in Java was by using anonymous inner classes. Java 8 introduced lambdas, which are
significantly more readable and should be used instead.</p>
<p>This rule is automatically disabled when the project’s <code>sonar.java.source</code> is lower than <code>8</code>, as lambda expressions were
introduced in Java 8.</p>
<h3>Code examples</h3>
<h4>Noncompliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
myCollection.stream().map(new Function&lt;String,String&gt;() { // Noncompliant, use a lambda expression instead
  @Override
  public String apply(String input) {
    return new StringBuilder(input).reverse().toString();
  }
})
  ...
</pre>
<h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
myCollection.stream()
  .map(input -&gt; new StringBuilder(input).reverse().toString()) // Compliant
    ...
</pre>
<h4>Noncompliant code example</h4>
<pre data-diff-id="2" data-diff-type="noncompliant">
Predicate&lt;String&gt; isEmpty = new Predicate&lt;String&gt;() { // Noncompliant, use a lambda expression instead
  @Override
  public boolean test(String myString) {
    return myString.isEmpty();
  }
};
</pre>
<h4>Compliant solution</h4>
<pre data-diff-id="2" data-diff-type="compliant">
Predicate&lt;String&gt; isEmpty = myString -&gt; myString.isEmpty(); // Compliant
</pre>
<h2>Resources</h2>
<ul>
  <li> <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html">Lambda Expressions - The Java™ Tutorials</a> </li>
</ul>

